package com.yumis.service.modules.user.service.impl;

import com.yumis.service.common.enums.HttpState;
import com.yumis.service.common.exception.GlobalException;
import com.yumis.service.common.vo.Response;
import com.yumis.service.model.pojo.Shop;
import com.yumis.service.model.pojo.UserCar;
import com.yumis.service.modules.user.mapper.UserCarMapper;
import com.yumis.service.modules.user.service.UserCarService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class UserCarServiceImpl implements UserCarService {
    @Resource
    private UserCarMapper userCarMapper;

    /**
     * 添加
     * @param userCar
     */
    @Override
    public void addUserCar(UserCar userCar) {
        int i=userCarMapper.insert(userCar);
        if (i!=1){
            throw new GlobalException(Response.buildResponse(HttpState.CREATED_FAILED));
        }
    }

    @Override
    public void deleteUserCarById(Long id) {
        int i=userCarMapper.deleteByPrimaryKey(id);
        if (i !=1){
            throw new GlobalException(Response.buildResponse(HttpState.DELETE_ERROR));
        }
    }

    @Override
    public UserCar queryUserCarById(Long id) {
        UserCar userCar=userCarMapper.selectByPrimaryKey(id);
        if (userCar ==null || userCar.equals("") ){
            throw new GlobalException(Response.buildResponse(HttpState.DATA_NOT_FOUNT));
        }
        return userCar;
    }

    @Override
    public void updateUserCar(UserCar userCar) {
        int i=userCarMapper.updateByPrimaryKeySelective(userCar);
        if (i !=1){
            throw new GlobalException(Response.buildResponse(HttpState.UPDATE_ERROR));
        }
    }
}
